import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart';
import 'package:video_ducafecat_flutter_v3/common/index.dart';

/// 文字消息
class MsgTextElemWidget extends StatelessWidget {
  final bool isSelf;
  final V2TimMessage message;

  const MsgTextElemWidget({
    super.key,
    required this.isSelf,
    required this.message,
  });

  Widget _buildView() {
    // 气泡框，自己的在右边，别人的在左边
    final borderRadius = isSelf
        ? const BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(2),
            bottomLeft: Radius.circular(10),
            bottomRight: Radius.circular(10))
        : const BorderRadius.only(
            topLeft: Radius.circular(2),
            topRight: Radius.circular(10),
            bottomLeft: Radius.circular(10),
            bottomRight: Radius.circular(10));

    return TextWidget.body1(
      message.textElem?.text ?? '',
      color: isSelf ? AppColors.onPrimary : AppColors.onSecondary,
    ).padding(all: AppSpace.listItem).decorated(
          borderRadius: borderRadius,
          color: isSelf ? AppColors.primary : AppColors.secondary,
        );
  }

  @override
  Widget build(BuildContext context) {
    return _buildView();
  }
}
